/*   1:    */ package com.jetbrains.licenseServer.openapi.util;
/*   2:    */ 
/*   3:    */

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */ 
/*  10:    */ class Entities
/*  11:    */ {
/*  12: 28 */   private static final String[][] a = { { "quot", "34" }, { "amp", "38" }, { "lt", "60" }, { "gt", "62" } };
/*  13: 34 */   private static final String[][] b = { { "apos", "39" } };
/*  14: 47 */   public static final Entities XML = new Entities();
/*  15:    */   
/*  16:    */   static
/*  17:    */   {
/*  18: 48 */     XML.addEntities(a);
/*  19: 49 */     XML.addEntities(b);
/*  20:    */   }
/*  21:    */   
/*  22:    */   static abstract interface EntityMap
/*  23:    */   {
/*  24:    */     public abstract void add(String paramString, int paramInt);
/*  25:    */     
/*  26:    */     public abstract String name(int paramInt);
/*  27:    */     
/*  28:    */     public abstract int value(String paramString);
/*  29:    */   }
/*  30:    */   
/*  31:    */   static class PrimitiveEntityMap
/*  32:    */     implements Entities.EntityMap
/*  33:    */   {
/*  34: 85 */     private Map a = new HashMap();
/*  35: 87 */     private IntHashMap b = new IntHashMap();
/*  36:    */     
/*  37:    */     public void add(String paramString, int paramInt)
/*  38:    */     {
/*  39: 93 */       this.a.put(paramString, Integer.valueOf(paramInt));
/*  40: 94 */       this.b.put(paramInt, paramString);
/*  41:    */     }
/*  42:    */     
/*  43:    */     public String name(int paramInt)
/*  44:    */     {
/*  45:101 */       return (String)this.b.get(paramInt);
/*  46:    */     }
/*  47:    */     
/*  48:    */     public int value(String paramString)
/*  49:    */     {
/*  50:108 */       Object localObject = this.a.get(paramString);
/*  51:109 */       if (localObject == null) {
/*  52:110 */         return -1;
/*  53:    */       }
/*  54:112 */       return ((Integer)localObject).intValue();
/*  55:    */     }
/*  56:    */   }
/*  57:    */   
/*  58:    */   static abstract class MapIntMap
/*  59:    */     implements Entities.EntityMap
/*  60:    */   {
/*  61:    */     protected Map mapNameToValue;
/*  62:    */     protected Map mapValueToName;
/*  63:    */     
/*  64:    */     public void add(String paramString, int paramInt)
/*  65:    */     {
/*  66:125 */       this.mapNameToValue.put(paramString, Integer.valueOf(paramInt));
/*  67:126 */       this.mapValueToName.put(Integer.valueOf(paramInt), paramString);
/*  68:    */     }
/*  69:    */     
/*  70:    */     public String name(int paramInt)
/*  71:    */     {
/*  72:133 */       return (String)this.mapValueToName.get(Integer.valueOf(paramInt));
/*  73:    */     }
/*  74:    */     
/*  75:    */     public int value(String paramString)
/*  76:    */     {
/*  77:140 */       Object localObject = this.mapNameToValue.get(paramString);
/*  78:141 */       if (localObject == null) {
/*  79:142 */         return -1;
/*  80:    */       }
/*  81:144 */       return ((Integer)localObject).intValue();
/*  82:    */     }
/*  83:    */   }
/*  84:    */   
/*  85:    */   static class HashEntityMap
/*  86:    */     extends Entities.MapIntMap
/*  87:    */   {
/*  88:    */     public HashEntityMap()
/*  89:    */     {
/*  90:153 */       this.mapNameToValue = new HashMap();
/*  91:154 */       this.mapValueToName = new HashMap();
/*  92:    */     }
/*  93:    */   }
/*  94:    */   
/*  95:    */   static class TreeEntityMap
/*  96:    */     extends Entities.MapIntMap
/*  97:    */   {
/*  98:    */     public TreeEntityMap()
/*  99:    */     {
/* 100:163 */       this.mapNameToValue = new TreeMap();
/* 101:164 */       this.mapValueToName = new TreeMap();
/* 102:    */     }
/* 103:    */   }
/* 104:    */   
/* 105:    */   static class LookupEntityMap
/* 106:    */     extends Entities.PrimitiveEntityMap
/* 107:    */   {
/* 108:    */     private String[] c;
/* 109:171 */     private int d = 256;
/* 110:    */     
/* 111:    */     public String name(int paramInt)
/* 112:    */     {
/* 113:177 */       if (paramInt < this.d) {
/* 114:178 */         return a()[paramInt];
/* 115:    */       }
/* 116:180 */       return super.name(paramInt);
/* 117:    */     }
/* 118:    */     
/* 119:    */     private String[] a()
/* 120:    */     {
/* 121:191 */       if (this.c == null) {
/* 122:192 */         b();
/* 123:    */       }
/* 124:194 */       return this.c;
/* 125:    */     }
/* 126:    */     
/* 127:    */     private void b()
/* 128:    */     {
/* 129:203 */       this.c = new String[this.d];
/* 130:204 */       for (int i = 0; i < this.d; i++) {
/* 131:205 */         this.c[i] = super.name(i);
/* 132:    */       }
/* 133:    */     }
/* 134:    */   }
/* 135:    */   
/* 136:    */   static class ArrayEntityMap
/* 137:    */     implements Entities.EntityMap
/* 138:    */   {
/* 139:211 */     protected int growBy = 100;
/* 140:213 */     protected int size = 0;
/* 141:    */     protected String[] names;
/* 142:    */     protected int[] values;
/* 143:    */     
/* 144:    */     public ArrayEntityMap()
/* 145:    */     {
/* 146:223 */       this.names = new String[this.growBy];
/* 147:224 */       this.values = new int[this.growBy];
/* 148:    */     }
/* 149:    */     
/* 150:    */     public ArrayEntityMap(int paramInt)
/* 151:    */     {
/* 152:234 */       this.growBy = paramInt;
/* 153:235 */       this.names = new String[paramInt];
/* 154:236 */       this.values = new int[paramInt];
/* 155:    */     }
/* 156:    */     
/* 157:    */     public void add(String paramString, int paramInt)
/* 158:    */     {
/* 159:243 */       ensureCapacity(this.size + 1);
/* 160:244 */       this.names[this.size] = paramString;
/* 161:245 */       this.values[this.size] = paramInt;
/* 162:246 */       this.size += 1;
/* 163:    */     }
/* 164:    */     
/* 165:    */     protected void ensureCapacity(int paramInt)
/* 166:    */     {
/* 167:255 */       if (paramInt > this.names.length)
/* 168:    */       {
/* 169:256 */         int i = Math.max(paramInt, this.size + this.growBy);
/* 170:257 */         String[] arrayOfString = new String[i];
/* 171:258 */         System.arraycopy(this.names, 0, arrayOfString, 0, this.size);
/* 172:259 */         this.names = arrayOfString;
/* 173:260 */         int[] arrayOfInt = new int[i];
/* 174:261 */         System.arraycopy(this.values, 0, arrayOfInt, 0, this.size);
/* 175:262 */         this.values = arrayOfInt;
/* 176:    */       }
/* 177:    */     }
/* 178:    */     
/* 179:    */     public String name(int paramInt)
/* 180:    */     {
/* 181:270 */       for (int i = 0; i < this.size; i++) {
/* 182:271 */         if (this.values[i] == paramInt) {
/* 183:272 */           return this.names[i];
/* 184:    */         }
/* 185:    */       }
/* 186:275 */       return null;
/* 187:    */     }
/* 188:    */     
/* 189:    */     public int value(String paramString)
/* 190:    */     {
/* 191:282 */       for (int i = 0; i < this.size; i++) {
/* 192:283 */         if (this.names[i].equals(paramString)) {
/* 193:284 */           return this.values[i];
/* 194:    */         }
/* 195:    */       }
/* 196:287 */       return -1;
/* 197:    */     }
/* 198:    */   }
/* 199:    */   
/* 200:    */   static class BinaryEntityMap
/* 201:    */     extends Entities.ArrayEntityMap
/* 202:    */   {
/* 203:    */     public BinaryEntityMap() {}
/* 204:    */     
/* 205:    */     public BinaryEntityMap(int paramInt)
/* 206:    */     {
/* 207:307 */       super();
/* 208:    */     }
/* 209:    */     
/* 210:    */     private int a(int paramInt)
/* 211:    */     {
/* 212:318 */       int i = 0;
/* 213:319 */       int j = this.size - 1;
/* 214:321 */       while (i <= j)
/* 215:    */       {
/* 216:322 */         int k = i + j >> 1;
/* 217:323 */         int m = this.values[k];
/* 218:325 */         if (m < paramInt) {
/* 219:326 */           i = k + 1;
/* 220:327 */         } else if (m > paramInt) {
/* 221:328 */           j = k - 1;
/* 222:    */         } else {
/* 223:330 */           return k;
/* 224:    */         }
/* 225:    */       }
/* 226:333 */       return -(i + 1);
/* 227:    */     }
/* 228:    */     
/* 229:    */     public void add(String paramString, int paramInt)
/* 230:    */     {
/* 231:340 */       ensureCapacity(this.size + 1);
/* 232:341 */       int i = a(paramInt);
/* 233:342 */       if (i > 0) {
/* 234:343 */         return;
/* 235:    */       }
/* 236:345 */       i = -(i + 1);
/* 237:346 */       System.arraycopy(this.values, i, this.values, i + 1, this.size - i);
/* 238:347 */       this.values[i] = paramInt;
/* 239:348 */       System.arraycopy(this.names, i, this.names, i + 1, this.size - i);
/* 240:349 */       this.names[i] = paramString;
/* 241:350 */       this.size += 1;
/* 242:    */     }
/* 243:    */     
/* 244:    */     public String name(int paramInt)
/* 245:    */     {
/* 246:357 */       int i = a(paramInt);
/* 247:358 */       if (i < 0) {
/* 248:359 */         return null;
/* 249:    */       }
/* 250:361 */       return this.names[i];
/* 251:    */     }
/* 252:    */   }
/* 253:    */   
/* 254:366 */   EntityMap map = new LookupEntityMap();
/* 255:    */   
/* 256:    */   public void addEntities(String[][] paramArrayOfString)
/* 257:    */   {
/* 258:376 */     for (String[] arrayOfString1 : paramArrayOfString) {
/* 259:377 */       addEntity(arrayOfString1[0], Integer.parseInt(arrayOfString1[1]));
/* 260:    */     }
/* 261:    */   }
/* 262:    */   
/* 263:    */   public void addEntity(String paramString, int paramInt)
/* 264:    */   {
/* 265:390 */     this.map.add(paramString, paramInt);
/* 266:    */   }
/* 267:    */   
/* 268:    */   public String entityName(int paramInt)
/* 269:    */   {
/* 270:402 */     return this.map.name(paramInt);
/* 271:    */   }
/* 272:    */   
/* 273:    */   public int entityValue(String paramString)
/* 274:    */   {
/* 275:414 */     return this.map.value(paramString);
/* 276:    */   }
/* 277:    */   
/* 278:    */   public String escape(String paramString)
/* 279:    */   {
/* 280:431 */     StringWriter localStringWriter = a(paramString);
/* 281:    */     try
/* 282:    */     {
/* 283:433 */       escape(localStringWriter, paramString);
/* 284:    */     }
/* 285:    */     catch (IOException localIOException) {}
/* 286:438 */     return localStringWriter.toString();
/* 287:    */   }
/* 288:    */   
/* 289:    */   public void escape(Writer paramWriter, String paramString)
/* 290:    */     throws IOException
/* 291:    */   {
/* 292:455 */     int i = paramString.length();
/* 293:456 */     for (int j = 0; j < i; j++)
/* 294:    */     {
/* 295:457 */       int k = paramString.charAt(j);
/* 296:458 */       String str = entityName(k);
/* 297:459 */       if (str == null)
/* 298:    */       {
/* 299:460 */         if (k > 127)
/* 300:    */         {
/* 301:461 */           paramWriter.write("&#");
/* 302:462 */           paramWriter.write(Integer.toString(k, 10));
/* 303:463 */           paramWriter.write(59);
/* 304:    */         }
/* 305:    */         else
/* 306:    */         {
/* 307:465 */           paramWriter.write(k);
/* 308:    */         }
/* 309:    */       }
/* 310:    */       else
/* 311:    */       {
/* 312:468 */         paramWriter.write(38);
/* 313:469 */         paramWriter.write(str);
/* 314:470 */         paramWriter.write(59);
/* 315:    */       }
/* 316:    */     }
/* 317:    */   }
/* 318:    */   
/* 319:    */   public String unescape(String paramString)
/* 320:    */   {
/* 321:489 */     int i = paramString.indexOf('&');
/* 322:490 */     if (i < 0) {
/* 323:491 */       return paramString;
/* 324:    */     }
/* 325:493 */     StringWriter localStringWriter = a(paramString);
/* 326:    */     try
/* 327:    */     {
/* 328:495 */       a(localStringWriter, paramString, i);
/* 329:    */     }
/* 330:    */     catch (IOException localIOException) {}
/* 331:500 */     return localStringWriter.toString();
/* 332:    */   }
/* 333:    */   
/* 334:    */   private StringWriter a(String paramString)
/* 335:    */   {
/* 336:511 */     return new StringWriter((int)(paramString.length() + paramString.length() * 0.1D));
/* 337:    */   }
/* 338:    */   
/* 339:    */   public void unescape(Writer paramWriter, String paramString)
/* 340:    */     throws IOException
/* 341:    */   {
/* 342:528 */     int i = paramString.indexOf('&');
/* 343:529 */     if (i < 0) {
/* 344:530 */       paramWriter.write(paramString);
/* 345:    */     } else {
/* 346:532 */       a(paramWriter, paramString, i);
/* 347:    */     }
/* 348:    */   }
/* 349:    */   
/* 350:    */   private void a(Writer paramWriter, String paramString, int paramInt)
/* 351:    */     throws IOException
/* 352:    */   {
/* 353:546 */     paramWriter.write(paramString, 0, paramInt);
/* 354:547 */     int i = paramString.length();
/* 355:548 */     for (int j = paramInt; j < i; j++)
/* 356:    */     {
/* 357:549 */       int k = paramString.charAt(j);
/* 358:550 */       if (k == 38)
/* 359:    */       {
/* 360:551 */         int m = j + 1;
/* 361:552 */         int n = paramString.indexOf(';', m);
/* 362:553 */         if (n == -1)
/* 363:    */         {
/* 364:554 */           paramWriter.write(k);
/* 365:    */         }
/* 366:    */         else
/* 367:    */         {
/* 368:557 */           int i1 = paramString.indexOf('&', j + 1);
/* 369:558 */           if ((i1 != -1) && (i1 < n))
/* 370:    */           {
/* 371:560 */             paramWriter.write(k);
/* 372:    */           }
/* 373:    */           else
/* 374:    */           {
/* 375:563 */             String str = paramString.substring(m, n);
/* 376:564 */             int i2 = -1;
/* 377:565 */             int i3 = str.length();
/* 378:566 */             if (i3 > 0) {
/* 379:567 */               if (str.charAt(0) == '#')
/* 380:    */               {
/* 381:569 */                 if (i3 > 1)
/* 382:    */                 {
/* 383:570 */                   int i4 = str.charAt(1);
/* 384:    */                   try
/* 385:    */                   {
/* 386:572 */                     switch (i4)
/* 387:    */                     {
/* 388:    */                     case 88: 
/* 389:    */                     case 120: 
/* 390:575 */                       i2 = Integer.parseInt(str.substring(2), 16);
/* 391:576 */                       break;
/* 392:    */                     default: 
/* 393:579 */                       i2 = Integer.parseInt(str.substring(1), 10);
/* 394:    */                     }
/* 395:582 */                     if (i2 > 65535) {
/* 396:583 */                       i2 = -1;
/* 397:    */                     }
/* 398:    */                   }
/* 399:    */                   catch (NumberFormatException localNumberFormatException)
/* 400:    */                   {
/* 401:586 */                     i2 = -1;
/* 402:    */                   }
/* 403:    */                 }
/* 404:    */               }
/* 405:    */               else {
/* 406:590 */                 i2 = entityValue(str);
/* 407:    */               }
/* 408:    */             }
/* 409:594 */             if (i2 == -1)
/* 410:    */             {
/* 411:595 */               paramWriter.write(38);
/* 412:596 */               paramWriter.write(str);
/* 413:597 */               paramWriter.write(59);
/* 414:    */             }
/* 415:    */             else
/* 416:    */             {
/* 417:599 */               paramWriter.write(i2);
/* 418:    */             }
/* 419:601 */             j = n;
/* 420:    */           }
/* 421:    */         }
/* 422:    */       }
/* 423:    */       else
/* 424:    */       {
/* 425:603 */         paramWriter.write(k);
/* 426:    */       }
/* 427:    */     }
/* 428:    */   }
/* 429:    */ }



/* Location:           E:\idea\

 * Qualified Name:     com.jetbrains.licenseServer.openapi.util.Entities

 * JD-Core Version:    0.7.0.1

 */